# encoding: utf-8

import os
import time
import pyautogui
import win32gui
import keyboard
from framework.utils.KeyBoardUtil import *
from framework.utils.MouseUtil import *
from framework.cores.UI import *
from framework.utils.PinYinUtil import *
# from wxauto import *

class WxqUtil:
    def __init__(self):
        pass

    @classmethod
    def openwxq(self,wxqName):
        os.system("D:\WeChat\WeChat.exe")
        time.sleep(1)
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 1920, 1040, True)
        time.sleep(1)
        # 点击通讯录
        pyautogui.click(24, 149)
        time.sleep(1)
        # 搜索指定的微信群
        KeyBoardUtil.inputChnText(180, 40, wxqName)
        time.sleep(1)
        pyautogui.press('enter')
        time.sleep(1)
        return 0

    @classmethod
    def clickTextWindow(cls):
        KeyBoardUtil.click(430, 981)

    @classmethod
    def clickTextWindow1440X900(cls):
        # KeyBoardUtil.click(364, 772)
        pass

    @classmethod
    def openwxqBywin10(cls,wxqName,dir):
        os.system(dir)
        time.sleep(1)
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 1920, 1080, True)
        time.sleep(1)
        # 点击通讯录
        pyautogui.click(24, 149)
        time.sleep(0.5)
        # 搜索指定的微信群
        KeyBoardUtil.inputChnText(180,40,wxqName)
        time.sleep(2)
        pyautogui.press('enter')
        time.sleep(2)
        return 0

    @classmethod
    def openWxOnly(cls):
        os.system("D:\WeChat\WeChat.exe")
        time.sleep(1)
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 1920, 1080, True)
        time.sleep(1)

    @classmethod
    def openwxqBy1440X900(cls,wxqName,dir):
        os.system(dir)
        time.sleep(1)
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 1920, 1080, True)
        time.sleep(1)
        '''
        title = UI.getCurrentTitle()
        if title != "微信":
            time.sleep(2)
            pyautogui.click(428, 881)
        
        time.sleep(2)
        pyautogui.click(27, 153)
        '''
        # 点击通讯录
        pyautogui.click(27, 153)
        time.sleep(0.5)
        # 搜索指定的微信群
        KeyBoardUtil.inputChnText(90,36,wxqName)
        time.sleep(2)
        pyautogui.press('enter')
        time.sleep(2)
        return 0

    @classmethod
    def openwxWindow1440X900(cls,dir):
        os.system(dir)
        time.sleep(1)
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 1440, 900, True)
        time.sleep(1)

    @classmethod
    def openwxWindow(cls,wxqName,dir):
        os.system(dir)
        time.sleep(1)
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 1920, 1080, True)
        time.sleep(1)

    @classmethod
    def clickWxBywin10(cls,wxqName):
        # 搜索指定的微信群
        KeyBoardUtil.inputChnText(180,40,wxqName)
        time.sleep(2)
        pyautogui.press('enter')
        time.sleep(2)

    @classmethod
    def clickWxBy1440X900(cls,wxqName):
        # 搜索指定的微信群
        KeyBoardUtil.inputChnText(125,36,wxqName)
        time.sleep(2)
        pyautogui.press('enter')
        time.sleep(2)


    @classmethod
    def sendFile(cls,filename):
        #点击“发送文件夹”按钮
        MouseUtil.click(369,918)
        UI.sleep(2)
        KeyBoardUtil.inputTextDirect(filename)
        # 点击“打开按钮”按钮
        UI.sleep(1)
        MouseUtil.click(802, 732)
        # 点击“发送”按钮
        MouseUtil.click(1839, 1013)

    @classmethod
    def sendFile1920X1080(cls,filename):
        #点击“发送文件夹”按钮
        MouseUtil.click(372,921)
        UI.sleep(2)
        KeyBoardUtil.inputChnText(256,478,filename)
        # 点击“打开按钮”按钮
        UI.sleep(1)
        MouseUtil.click(785, 509)
        # 点击“发送”按钮
        MouseUtil.click(1800, 1013)

    @classmethod
    def sendFile1440X900(cls,filename):
        #点击“发送文件夹”按钮
        MouseUtil.click(369,917)
        UI.sleep(2)
        keyboard.write('D:\\tf\\' + filename)
        # 点击“打开按钮”按钮
        UI.sleep(1)
        pyautogui.hotkey('enter')
        # 点击“发送”按钮
        pyautogui.hotkey('enter')

    @classmethod
    def sendFile(cls,filename):
        #点击“发送文件夹”按钮
        MouseUtil.click(372,921)
        UI.sleep(2)
        KeyBoardUtil.inputChnText(256,478,filename)
        # 点击“打开按钮”按钮
        UI.sleep(1)
        MouseUtil.click(785, 509)
        # 点击“发送”按钮
        MouseUtil.click(1800, 1013)

    @classmethod
    def sendFileWin7(cls,filename):
        #点击“发送文件夹”按钮
        MouseUtil.click(369,811)
        UI.sleep(2)
        KeyBoardUtil.inputChnText(299,471,filename)
        # 点击“打开按钮”按钮
        UI.sleep(1)
        MouseUtil.click(760, 504)
        # 点击“发送”按钮
        MouseUtil.click(1800, 1013)

    @classmethod
    def sendText(cls, text):
        KeyBoardUtil.inputSimpleChnText(430, 981, text)
        pyautogui.press('enter')

    @classmethod
    def sendTextNoEnter(cls, text):
        KeyBoardUtil.inputSimpleChnText(430, 981, text)

    @classmethod
    def sendText1440X900(cls, text):
        # keyboard.write(text)
        KeyBoardUtil.inputSimpleChnText(1360, 963 , text)
        pyautogui.press('enter')

    @classmethod
    def sendTextNoEnter1440X900(cls, text):
        # keyboard.write(text)
        KeyBoardUtil.inputSimpleChnText(1360, 963 , text)

    @classmethod
    def sendPerson(cls,text):
        pyautogui.write("@")
        #pinyin = PinYinUtil.read(text)
        #pyautogui.write(pinyin)
        KeyBoardUtil.inputCopyChnText(text+" ")
        pyautogui.press('enter')

    @classmethod
    def showWx(cls):
        time.sleep(2)
        pyautogui.click(455, 882)

    '''
    @classmethod
    def send_msg(cls, wxq_name, msg_list=[], viewer_list=[]):
        # os.system("E:\微信\WeChat\WeChat.exe")
        os.system("D:\WeChat\WeChat.exe")
        wechat = WeChat()
        wechat.Search(wxq_name)  # 进入 wxq_name 聊天窗口
        wechat.EditMsg = wechat.UiaAPI.EditControl(Name=f'{wxq_name}')  # 切换发送消息前的窗口标题(wxauto兼容修改)
        wechat.UiaAPI.SwitchToThisWindow()
        wechat.EditMsg.SendKeys('{Ctrl}a', waitTime=0)
        for msg in msg_list:
            wechat.EditMsg.SendKeys(msg, waitTime=0)
            wechat.EditMsg.SendKeys('\n', waitTime=0)
        if viewer_list:
            for viewer in viewer_list:
                wechat.EditMsg.SendKeys(viewer, waitTime=0)
                wechat.EditMsg.SendKeys('{Enter}', waitTime=0)
        wechat.EditMsg.SendKeys('{Enter}', waitTime=0)

    @classmethod
    def open_wxq(cls, wxq_name):
        os.system("E:\微信\WeChat\WeChat.exe")
        # os.system("D:\WeChat\WeChat.exe")
        # 窗口最大化
        window = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(window, 0, 0, 960, 720, True)
        time.sleep(1)
        wechat = WeChat()
        wechat.Search(wxq_name)  # 进入 wxq_name 窗口
    '''

